package com.jkoss.action.jy;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.jkoss.biz.jy.JyCompsBiz;
import com.jkoss.pojo.jy.JiuyeGS;
import com.jkoss.pojo.oa.Emps;
import com.jkoss.tool.Page;

@Controller
@RequestMapping("/jy")
public class JiuyeCompsAction {
    
	@Autowired
	private JyCompsBiz jybiz;
	
	//查看全部企业
	@RequestMapping("listGs")
	public String listGs(HttpServletRequest req,Page<JiuyeGS> page){
		
		if(page==null){
			page=new Page<JiuyeGS>();
		}
		
		page.setResults(jybiz.listGs(page));
		req.setAttribute("page", page);
		
		return "listGs.jsp";
		//////
	}
	
	//查看单个企业
	@RequestMapping("oneGs")
	public String oneGs(HttpServletRequest req,Integer jyid){
		
		JiuyeGS gs=jybiz.findByJyid(jyid);
		req.setAttribute("gs", gs);
		
		return "shGs.jsp";
		
	}
	
	//添加企业
	@RequestMapping("addGs")
	public String addGs(HttpServletRequest req,JiuyeGS gs){
		Emps emp=(Emps) req.getSession().getAttribute("lgnUsr");
		
		gs.setEid(emp.getEid());
		gs.setJyaddtime(new Date());
		
		String msg=jybiz.addGs(gs);
		System.out.println("-----------------------"+msg);
		
		req.setAttribute("msg", msg);
		
		return listGs(req,null);
		
	}
	
	//删除数据
	@RequestMapping("delGs")
	public String delGs(HttpServletRequest req,Integer jyid){
		String msg=jybiz.delGs(jyid);
		req.setAttribute("msg", msg);
		return listGs(req,null);
	}
	
	//去编辑页面
	@RequestMapping("toUpGs")
	public String toUpGS(HttpServletRequest req,Integer jyid){
		
		JiuyeGS gs=jybiz.findByJyid(jyid);
		req.setAttribute("gs", gs);
		
		return "upGs.jsp";	
	}
	
	@RequestMapping("upGs")
	public String upGs(HttpServletRequest req,JiuyeGS gs){
		JiuyeGS g=jybiz.findByJyid(gs.getJyid());
		g.setJytel(gs.getJytel());
		g.setJyeqq(gs.getJyeqq());
		g.setJyaddrss(gs.getJyaddrss());
		g.setJydescb(gs.getJydescb());
		g.setJydgr(gs.getJydgr());
		g.setJyetel(gs.getJyetel());
		g.setJyname(gs.getJyname());
		g.setJyempname(gs.getJyempname());
		g.setJyaddtime(new Date());
		String msg=jybiz.upGs(g);
		req.setAttribute("msg", msg);
		return listGs(req,null);
		
	}
	
	
	
	
	
	
}
